///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2011. Dimarik
//
///////////////////////////////////////////////////////////////////////////////

package
{

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.net.URLRequest;

import ru.goodcore.core.GoodCore;
import ru.goodcore.display.ui.core.UIComponent;

/**
 *  @author				Dimarik
 *  @version			1.0
 *  @langversion		3.0
 *  @playerversion		9.0
 * 
 */
[SWF(width="600", height="400", frameRate="21", backgroundColor="#E0EEEE")]

public class LayoutTestLoader extends GoodCore {

	//-------------------------------------------------------------------------
	//
	//   Constructor
	//
	//-------------------------------------------------------------------------

	public function LayoutTestLoader() {
		super();
		super.percentHeight = super.percentWidth = 100;
		super.color = 0xFF00FF;
		//super.addEventListener(Event.ADDED_TO_STAGE, this.creationComplete);
		//const g:Graphics = this.graphics;
		//g.lineStyle(1, 0x00FF00, 1);
		//g.drawRect(0, 0, 100, 100);
	}

	//-------------------------------------------------------------------------
	//
	//   Private variables
	//
	//-------------------------------------------------------------------------

	//-------------------------------------------------------------------------
	//
	//   Private methods
	//
	//-------------------------------------------------------------------------

	protected override function creationComplete():void {
		super.creationComplete();
		//(event.target as IEventDispatcher).removeEventListener(event.type, arguments.callee);
		super.stage.scaleMode = StageScaleMode.NO_SCALE;
		super.stage.align = StageAlign.TOP_LEFT;

		const loader:Loader = new Loader();
		const li:LoaderInfo = loader.contentLoaderInfo;
		li.addEventListener(Event.COMPLETE, this.handler_complte);
		//super.stage.addChild(loader);
		//loader.load( new URLRequest('UIComponentModule.swf') );
		loader.load( new URLRequest('LayoutTest.swf') );
	}

	//-------------------------------------------------------------------------
	//
	//   Events handlers
	//
	//-------------------------------------------------------------------------

	private function handler_complte(event:Event):void {
		trace('loaded');
		const li:LoaderInfo = event.target as LoaderInfo;
		li.removeEventListener(Event.COMPLETE, this.handler_complte);
		//super.stage.addChild(li.loader);
		//super.stage.addChildAt(li.loader, 0);
		//super.stage.removeChild(li.loader);
		super.addChild(li.content);
		//super.addChild(li.loader);
		//super.stage.addChild(li.content);
		//super.stage.addChildAt(li.content, 0);
		//super.stage.removeChild(li.loader);
		//const ui1:UIComponent = new UIComponent();
		//ui1.percentWidth = 90;
		//ui1.percentHeight = 60;
		//super.stage.addChild(ui1);
	}

}
}